package com.wd.live.viewmodel

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.amap.api.location.AMapLocation
import com.wd.live.BaseConstant
import com.wd.live.tool.LocalData
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

class MainViewModel : BaseViewModel() {
    /**
     * 模拟数据
     */
    fun getNearListMock(longitude: String?, latitude: String?, sex: Int) {
        nearList.value = arrayListOf<LocalData.BroadcasterInfo>().apply {
            for (i in 1..100) {
                add(
                    LocalData.BroadcasterInfo(
                        "阿德",
                        "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTIbic8DRlaWH6bexeZdEmasJqurte44MhoB6UpUwx6uAhibOSQ8emDxdpBlSoyib0FcN9B7xqsO6jrDA/132",
                        longitude = "116.16192",
                        latitude = "40.05246",
                        liveId = 2809,
                        sex = 1,
                        follow = 20000
                    )
                )
            }
        }
    }

    fun getNearList(longitude: String?, latitude: String?, sex: Int) {
        val map = HashMap<String, Any?>()
        map["longitude"] = longitude
        map["latitude"] = latitude
        map["sex"] = sex
        map["range"] = 5000
        BaseConstant.userId?.let { systemApi?.getNearList(it, map) }?.let {
            it.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe({ bean ->
                    nearList.value = bean.result
                    Log.d("provideSystemApi", bean.toString())
                }, { error ->
                    Log.d("provideSystemApi", error.message.toString())
                })
        }
    }

    val nearList: MutableLiveData<ArrayList<LocalData.BroadcasterInfo>> by lazy {
        MutableLiveData<ArrayList<LocalData.BroadcasterInfo>>()
    }

    val location: MutableLiveData<AMapLocation> by lazy {
        MutableLiveData<AMapLocation>()
    }
}
